/*
 * @lc app=leetcode.cn id=1629 lang=javascript
 *
 * [1629] 按键持续时间最长的键
 */

// @lc code=start
/**
 * @param {number[]} releaseTimes
 * @param {string} keysPressed
 * @return {character}
 */
var slowestKey = function (releaseTimes, keysPressed) {
  let max = releaseTimes[0], ch = keysPressed[0];
  for (let i = 0; i < releaseTimes.length; i++) {
    if (releaseTimes[i] - releaseTimes[i - 1] > max) {
      max = releaseTimes[i] - releaseTimes[i - 1];
      ch = keysPressed[i];
    } else if (releaseTimes[i] - releaseTimes[i - 1] === max) {
      ch = ch > keysPressed[i] ? ch : keysPressed[i];
    }
  }
  return ch;
};
// @lc code=end

